<!--
 * @Autor: Haiting Zhao
 * @Date: 2021-12-07 14:56:01
 * @LastEditors: xu xuejia
 * @LastEditTime: 2021-12-21 20:53:37
 * @Description: file content
 * @FilePath: \Management-of-Scientific-Research-in-Universities-Front\src\views\kyproject\EndApply.vue
-->
<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ name:'WorkPlace' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>科研项目</el-breadcrumb-item>
      <el-breadcrumb-item>结题申请</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="sousuo">
      <el-input v-model="input" style="width:50%" placeholder="请输入内容" />
      <el-button type="primary" @click="search">搜 索</el-button>
    </div>
    <div class="contain">

      <div class="shaixuan" :style="iszhankai?'height:105px':'height:35px'">
        <span class="danwei">来源单位：</span>
        <div class="everysc" :style="iszhankai?'overflow:visible':'overflow:hidden'">
          <div :class="f?'xueyuanxz':'xueyuan'" @click="getuserprojects()">全部</div>
          <div v-for="(item,index) in xueyuan" :key="index" :class="index===number?'xueyuanxz':'xueyuan'" @click="sxxs(item, index)">
            {{ item.departmentName }}
          </div>
          <div v-if="!iszhankai" class="zhankai" @click="collapse">展开 <i class="el-icon-arrow-down" /></div>
          <div v-if="iszhankai" class="zhankai" @click="collapse">折叠 <i class="el-icon-arrow-up" /></div>
        </div>
      </div>

      <div class="shaixuan2">
        <span class="danwei">项目进展：</span>
        <div class="everysc">
          <div v-for="(item,index) in projectstatus" :key="index" :class="index===number1?'xueyuanxz':'xueyuan'" @click="getdown(item, index)">
            {{ item.name }}
          </div>
        </div>
      </div>

      <el-row v-if="!isnull" id="xiangmukapian">
        <el-col
          v-for="(project, index) in projectlist"
          :key="index"
          style="margin-left:30px;margin-top:40px;"
          :span="5"
          :offset="index > projectlength ? 2 : 0"
        >
          <el-card class="carddiv" :body-style="{ padding: '0px' }">
            <div @click="endapply(index)">
              <img
                :src="project.fileMap.logo"
                class="image"
                width="200px"
                height="180px"
              >
              <div style="padding: 10px">
                <span style="display:inline-block; width:150px;overflow:hidden; white-space:nowrap; text-overflow:ellipsis; ">{{ project.projectName }}</span>
                <div class="bottom">
                  <!-- <time class="time">{{ currentDate }}</time> -->
                  <el-button type="text" class="button" @click="endapply(index)">结题</el-button>
                </div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <div v-if="isnull" class="wu">
        暂无数据
      </div>
      <el-pagination
        style="text-align: right;"
        :current-page="paginations.page_index"
        :page-sizes="paginations.page_sizes"
        :page-size="paginations.page_size"
        :layout="paginations.layout"
        :total="paginations.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>
<script>
import axios from 'axios'
import crypto from '../../crypto/crypto'
export default {
  name: 'Endapply',
  data() {
    return {
      xueyuan: [],
      bumen: '',
      zhuangtai: '',
      projectstatus: [
        { name: '全部',
          id: '' },
        { name: '已申请',
          id: 1 },
        { name: '初审通过',
          id: 2 },
        { name: '二审通过',
          id: 3 },
        { name: '已申请结题',
          id: 4 },
        { name: '已完成',
          id: 5 }],
      number1: 0, // 部门
      number: -1, // 学院
      f: 1,
      statusform: {
        userId: '',
        departmentId: '',
        statusId: '',
        pageNum: '',
        pageSize: ''
      },
      currentPage1: 2,
      isnull: 0,
      iszhankai: false,
      input: '',
      userid: this.$store.getters.getuserId, // 获取用户id
      projectlist: [], // 项目列表
      projectlength: '', // 获取到的长度
      imgurl: '', // logo
      currentDate: '', // 时间
      ctlist: [], // 记录结题方式数组
      paginations: {
        currentPage: 1,
        page_index: 1, // 当前页
        total: 0, // 总数
        page_size: 8, // 一页显示多少
        page_sizes: [4, 8, 12, 16], // 一页显示多少
        layout: 'total, sizes, prev, pager, next',
        pageflag: 0
      }
    }
  },
  created() {
    this.getuserprojects() // 获取本人项目列表
    this.getxuanyuan() // 获取学院列表
    // console.log(this.$transition.getoneDictionary('achievementType', 1))
  },
  methods: {

    /**
     * @description: 获取本人项目列表
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    getuserprojects() {
      this.f = 1
      this.number = -1
      this.number1 = 0
      this.bumen = ''
      this.paginations.pageflag = 0
      axios.get('/project/', { params: { userId: this.userid, pageNum: this.paginations.page_index, pageSize: this.paginations.page_size }})
        .then(res => {
          // this.projectlist = res.data.data.list
          // this.projectlength = this.projectlist.length
          // for (let index = 0; index < this.projectlist.length; index++) { // 遍历记录每个项目的结题形式 记录在ctlist中
          //   this.ctlist[index] = this.projectlist[index].ctId
          // }
          if (res.data.data !== null) {
            this.isnull = 0
            this.projectlist = res.data.data.list
            this.projectlength = this.projectlist.length
            this.paginations.total = res.data.data.total
            for (let index = 0; index < this.projectlist.length; index++) { // 遍历记录每个项目的结题形式 记录在ctlist中
              this.ctlist[index] = this.projectlist[index].ctId
            }
          } else {
            this.isnull = 1
            this.paginations.total = 0
          }
        })
        .catch(err => {
          console.error(err)
        })
    },

    /**
     * @description: 搜索项目
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    search() {
      axios.get('/project/getProjectByName', { params: { userId: this.userid, projectName: this.input }})
        .then((res) => {
          this.projectlist = res.data.data.list
          this.projectlength = this.projectlist.length
          this.paginations.total = res.data.data.total
          for (let index = 0; index < this.projectlist.length; index++) { // 遍历记录每个项目的结题形式 记录在ctlist中
            this.ctlist[index] = this.projectlist[index].ctId
          }
        })
        .catch(err => {
          console.error(err)
        })
    },

    /**
     * @description: 根据学院分类
     * @param {*} item
     * @param {*} index
     * @return {*}
     * @author: Haiting Zhao
     */
    sxxs(item, index) {
      this.f = 0
      this.number = index
      this.number1 = 0 // 状态为全部
      this.bumen = item.departmentId
      this.paginations.pageflag = 1
      this.sxxsindex()
    },
    sxxsindex() {
      axios.get('/project/getProjectByDepartmentAndUserId', {
        params: {
          userId: this.userid,
          departmentId: this.bumen,
          pageNum: this.paginations.page_index,
          pageSize: this.paginations.page_size
        }
      })
        .then((res) => {
          if (res.data.data !== null) {
            this.isnull = 0
            this.projectlist = res.data.data.list
            this.projectlength = this.projectlist.length
            this.paginations.total = res.data.data.total
            for (let index = 0; index < this.projectlist.length; index++) { // 遍历记录每个项目的结题形式 记录在ctlist中
              this.ctlist[index] = this.projectlist[index].ctId
            }
          } else {
            this.isnull = 1
            this.paginations.total = 0
          }
        })
        .catch(err => {
          console.error(err)
        })
    },

    /**
     * @description: 根据学院和部门分类
     * @param {*} item
     * @param {*} index
     * @return {*}
     * @author: Haiting Zhao
     */
    getdown(item, index) {
      this.number1 = index
      this.paginations.pageflag = 2
      this.zhuangtai = item.id
      // console.log(item.id)
      this.getdownindex()
    },
    getdownindex() {
      this.statusform.userId = this.userid
      this.statusform.departmentId = this.bumen
      this.statusform.statusId = this.zhuangtai
      this.statusform.pageNum = this.paginations.page_index
      this.statusform.pageSize = this.paginations.page_size
      axios.post('project/getProjetByInfo/', this.statusform)
        .then((res) => {
          if (res.data.data !== null) {
            this.isnull = 0
            this.projectlist = res.data.data.list
            this.projectlength = this.projectlist.length
            this.paginations.total = res.data.data.total
            for (let index = 0; index < this.projectlist.length; index++) { // 遍历记录每个项目的结题形式 记录在ctlist中
              this.ctlist[index] = this.projectlist[index].ctId
            }
          } else {
            this.isnull = 1
            this.paginations.total = 0
          }
        })
        .catch(err => {
          console.error(err)
        })
    },

    /**
     * @description: 获取学院
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    getxuanyuan() {
      axios.get('/dictionary/searchAll/department')
        .then(res => {
          this.xueyuan = res.data.data
        })
        .catch(err => {
          console.error(err)
        })
    },

    /**
     * @description: 展开学院
     * @param {*}
     * @return {*}
     * @author: Haiting Zhao
     */
    collapse() {
      this.iszhankai = !this.iszhankai
    },

    /**
     * @description: 点击进入结题申请
     * @param {*} index
     * @return {*}
     * @author: Haiting Zhao
     */
    endapply(index) {
      // console.log(index)
      // console.log(this.ctlist[index])
      sessionStorage.setItem('projectdetail', JSON.stringify(this.projectlist[index]))
      if (this.ctlist[index] === 1) { // 论文结题
        this.$router.push('/' + crypto.set('31'))
        // console.log('论文结题')
        // console.log(this.projectlist[index].projectName)
      } else if (this.ctlist[index] === 2) { // 获奖结题
        this.$router.push('/' + crypto.set('32'))
        // console.log('获奖结题')
        // console.log(this.$transition.getoneDictionary('achievementType', 1))
        // console.log(this.projectlist[index].projectName)
      } else if (this.ctlist[index] === 3) { // 专利结题
        this.$router.push('/' + crypto.set('33'))
        // console.log('专利结题')
        // console.log(this.projectlist[index].projectName)
      }
    },
    /**
     * @description: 一页几条
     * @param {*} val
     * @return {*}
     * @author: Haiting Zhao
     */
    handleSizeChange(val) {
      this.paginations.page_size = val
      if (this.paginations.pageflag === 0) {
        this.getuserprojects()
      } else if (this.paginations.pageflag === 1) {
        this.sxxsindex()
      } else {
        this.getdownindex()
      }
    },
    /**
     * @description: 第几页
     * @param {*} val
     * @return {*}
     * @author: Haiting Zhao
     */
    handleCurrentChange(val) {
      this.paginations.page_index = val
      if (this.paginations.pageflag === 0) {
        this.getuserprojects()
      } else if (this.paginations.pageflag === 1) {
        this.sxxsindex()
      } else {
        this.getdownindex()
      }
    }
  }
}
</script>
<style  lang="scss">
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.button {
  padding: 0;
  min-height: auto;
}

.image {
  width: 100%;
  display: block;
}

.sousuo{
  margin: 20px auto;
  padding-bottom: 30px;
  padding-left: 25%;
  border-bottom: 1px solid rgb(221, 221, 221);
}

.carddiv {
  cursor: pointer;
}
.carddiv:hover{
  transform: scale(1.05,1.05);
}
.shaixuan2{
  padding-bottom: 20px;
  height: 35px;
  border-bottom: 1px solid rgb(221, 221, 221);
  position: relative;
  .danwei{
    position: absolute;
    left: 82px;
    top: 8px;
    font-weight: 300;
  }
  .everysc{
    display: inline-block;
    display: flex;
    flex-flow:row wrap;
    width: 84%;
    height: 30px;
    overflow: hidden;
    position: relative;
    left: 150px;
    top: 5px;
    .xueyuan{
      font-size: 14px;
      font-weight: 200;
      height: 20px;
      padding: 2px 5px;
      text-align: center;
      margin: 2px 10px;
      cursor: pointer;
    }
    .xueyuan:hover{
      color: aliceblue;
      background-color: #409EFF;
      border-radius: 5px;
    }
    .xueyuanxz{
      font-size: 14px;
      font-weight: 200;
      height: 20px;
      padding: 2px 5px;
      text-align: center;
      margin: 2px 10px;
      cursor: pointer;
      color: aliceblue;
      background-color: #409EFF;
      border-radius: 5px;
    }
  }

}
.shaixuan{
  // height: 120px;
  padding-bottom: 20px;
  margin: 20px auto;
  transition: all .5s;
  border-bottom: 1px solid rgb(221, 221, 221);
  position: relative;
  .danwei{
    position: absolute;
    left: 82px;
    top: 1px;
    font-weight: 300;
  }
  .everysc{
    display: inline-block;
    display: flex;
    flex-flow:row wrap;
    width: 80%;
    height: 30px;
    overflow: hidden;
    position: relative;
    left: 150px;
    .xueyuan{
      font-size: 14px;
      font-weight: 200;
      height: 20px;
      padding: 2px 5px;
      text-align: center;
      margin: 2px 10px;
      cursor: pointer;
    }
    .xueyuan:hover{
      color: aliceblue;
      background-color: #409EFF;
      border-radius: 5px;
    }
    .xueyuanxz{
      font-size: 14px;
      font-weight: 200;
      height: 20px;
      padding: 2px 5px;
      text-align: center;
      margin: 2px 10px;
      cursor: pointer;
      color: aliceblue;
      background-color: #409EFF;
      border-radius: 5px;
    }
    .zhankai{
      position: absolute;
      top: 3px;
      right: 11px;
      margin-left: 10px;
      padding-left: 10px;
      font-weight: 300;
      cursor: pointer;
      color: #409EFF;
    }
  }
}
.wu{
    width: 200px;
    height: 120px;
    text-align: center;
    line-height: 120px;
    font-weight: 200;
    color: #aaadaf;
    margin: 100px auto;
}

</style>
